package com.cndongtai.listener;

import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;

import org.springframework.context.ApplicationContext;
import org.springframework.web.context.support.WebApplicationContextUtils;

import com.cndongtai.dao.impl.TorchnInverterCollectRecordDao;
import com.cndongtai.net.Server;
import com.cndongtai.net.analysis.WIFIMessageFilter;

public class WIFIListener implements ServletContextListener{
	
	private Server server = new Server(32897);

	@Override
	public void contextDestroyed(ServletContextEvent arg0) {
		server.interrupt();
	}

	@Override
	public void contextInitialized(ServletContextEvent arg0) {
		ApplicationContext springContext = WebApplicationContextUtils.getWebApplicationContext(arg0.getServletContext());
		WIFIMessageFilter.torchnInverterCollectRecordDao = (TorchnInverterCollectRecordDao) springContext.getBean("torchnInverterCollectRecordDao");
		if(WIFIMessageFilter.torchnInverterCollectRecordDao==null) {
			System.out.print("=========WIFIListener初始化失败=========");
		}
		server.start();
		System.out.print("=========WIFIListener启动成功=========");
	}

}
